package com.mytinyRPC.framework;


import java.io.Serializable;
import java.util.Objects;

/***
 * @Author HP
 * @Description //URL结构
 **/
public class URL implements Serializable {
    //ip地址
    private String hostname;
    //端口
    private Integer port;
    //权值
    private Integer weight=1;


    public String getHostname() {
        return hostname;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Integer getPort() {
        return port;
    }

    public URL(String hostname, Integer port, Integer weight) {
        this.hostname = hostname;
        this.port = port;
        this.weight = weight;
    }

    public URL(String hostname, Integer port) {
        this.hostname = hostname;
        this.port = port;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        URL url = (URL) o;
        return Objects.equals(hostname, url.hostname) &&
                Objects.equals(port, url.port) &&
                Objects.equals(weight, url.weight);
    }

    @Override
    public String toString() {
        return hostname + ':' + port +':'+ weight;
    }

    @Override
    public int hashCode() {
        return Objects.hash(hostname, port, weight);
    }
}
